package cn.edu.nju.utils;

import cn.edu.nju.exception.AdException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.time.DateUtils;

import java.util.Date;


/**
 * Created by thpffcj on 2019/8/26.
 */
public class CommonUtils {

    private static String[] parsePatterns = {
            "yyyy-MM-dd", "yyyy/MM/dd", "yyyy.MM.dd"
    };

    public static String md5(String value) {

        return DigestUtils.md5Hex(value).toUpperCase();
    }

    public static Date parseStringDate(String dateString) throws AdException {

      try {
          return DateUtils.parseDate(
                  dateString, parsePatterns
          );
      } catch (Exception ex) {
          throw new AdException(ex.getMessage());
      }
    }
}
